
class Counter
{
private:
	long full_CTR;
	long CTR;
	long tmp_CTR;

public:
	long start;
	long end;
 	long step;
	long carry;
	count_mode mode;
	
	Counter ()
	{
		start = 0;
		end = 10;
		carry = 0;
		step = 1;
		full_CTR = start;
		tmp_CTR = 0;
		mode = UP;
		
	}	

	void Reset(bool full_reset = true)
	{
		if (full_reset) carry = 0;
		
		CTR = (mode==UP) ? start : (end-1);
		tmp_CTR = start;
	}
	void Next()
	{
		tmp_CTR += step;
		full_CTR = tmp_CTR;
		tmp_CTR = ((tmp_CTR - start) % (end - start)) + start;
		carry += ((bool)(full_CTR > tmp_CTR));
		
		CTR = (mode==UP) ? tmp_CTR : end - tmp_CTR + start - 1;
	}
	
	long GetCTR ()
	{
		return CTR;
	}
	void Set (	long in_start,
				long in_end,
				long in_step=1,
				count_mode in_mode=UP)
	{
		start = in_start;
		end = in_end;
		step = in_step;
		mode = in_mode;
		
		(mode == UP) ? CTR = start : CTR = end - 1;
	}

	~Counter(){};
};

